package com.yixun.qfbao.hander;

import com.yixun.qfbao.api.service.PersonnelService;
import com.yixun.qfbao.apidto.UpdatePwdReqDto;
import com.yixun.qfbao.apidto.UpdatePwdResDto;
import com.yixun.qfbao.dto.base.BaseRequestDTO;
import com.yixun.qfbao.dto.base.BaseResponseDTO;
import com.yixun.qfbao.hander.base.CommonAbstractHander;
import com.yixun.qfbao.util.exception.TServerException;
import com.yixun.qfbao.vo.UpdatePwdReqVo;
import com.yixun.qfbao.xf.model.enums.ResultEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by Administrator on 2017/11/22.
 */
@Service("updatePwdHander")
public class UpdatePwdHander extends CommonAbstractHander {
    private static Logger logger= LoggerFactory.getLogger(UpdatePwdHander.class);

    @Autowired
    PersonnelService personnelService;
    @Override
    public BaseResponseDTO doBusiness(BaseRequestDTO reqDto) {
        UpdatePwdReqVo req = (UpdatePwdReqVo) reqDto;
        UpdatePwdReqDto resetPwdReqDto = req.getParams();
        BaseResponseDTO<UpdatePwdResDto> res = new BaseResponseDTO<UpdatePwdResDto>();
        UpdatePwdResDto resDto = new UpdatePwdResDto();
        try {
            resDto = personnelService.updatePwd(resetPwdReqDto);

            resDto.setResult(ResultEnum.SUCCESS.getNo());
            resDto.setResultMsg("重置成功");
        }catch (TServerException e){
            resDto.setResult(ResultEnum.FAIL.getNo());
            resDto.setResultMsg(e.getMessage());
        }catch (Exception e) {
            logger.error("UpdatePwdHander error: {}", e);
            resDto.setResult(ResultEnum.FAIL.getNo());
            resDto.setResultMsg("重置失败!");
        }
        res.setResData(resDto);
        res.setResult(resDto.getResult());
        return res;
    }
}
